package com.netintech.project.system.meeting.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.netintech.project.system.meeting.domain.MeetingApplication;
import com.netintech.project.system.meeting.mapper.MeetingApplicationMapper;
import com.netintech.project.system.meeting.service.MeetingApplicationService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.netintech.common.utils.text.Convert;

/**
 * 会议申请Service业务层处理
 *
 * @author admin
 * createTime 2020-09-18
 * lastModify admin
 * lastModifyTime 2020-09-18
 * group 电子政务小组
 */
@Service
public class MeetingApplicationServiceImpl implements MeetingApplicationService
{
    @Autowired
    private MeetingApplicationMapper meetingApplicationMapper;

    /**
     * 查询会议申请
     *
     * @param id 会议申请ID
     * @return 会议申请
     */
    @Override
    public MeetingApplication selectMeetingApplicationById(Long id)
    {
        return meetingApplicationMapper.selectMeetingApplicationById(id);
    }

    /**
     * 查询会议申请列表
     *
     * @param meetingApplication 会议申请
     * @return 会议申请
     */
    @Override
    public List<MeetingApplication> selectMeetingApplicationList(MeetingApplication meetingApplication)
    {
        return meetingApplicationMapper.selectMeetingApplicationList(meetingApplication);
    }

    /**
     * 新增会议申请
     *
     * @param meetingApplication 会议申请
     * @return 结果
     */
    @Override
    public int insertMeetingApplication(MeetingApplication meetingApplication)
    {
        return meetingApplicationMapper.insertMeetingApplication(meetingApplication);
    }

    /**
     * 修改会议申请
     *
     * @param meetingApplication 会议申请
     * @return 结果
     */
    @Override
    public int updateMeetingApplication(MeetingApplication meetingApplication)
    {
        return meetingApplicationMapper.updateMeetingApplication(meetingApplication);
    }

    /**
     * 删除会议申请对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMeetingApplicationByIds(String ids)
    {
        return meetingApplicationMapper.deleteMeetingApplicationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除会议申请信息
     *
     * @param id 会议申请ID
     * @return 结果
     */
    @Override
    public int deleteMeetingApplicationById(Long id)
    {
        return meetingApplicationMapper.deleteMeetingApplicationById(id);
    }


    /**
     * 查询日历会议数据
     * @param filterMap
     * @return
     */
    @Override
    public List<MeetingApplication> queryCalendarMeetingData(Map<String, Object> filterMap) {
        return meetingApplicationMapper.queryCalendarByDateParagraph(filterMap);
    }


    /**
     * 查询更多
     * @param filterMap
     * @return
     */
    @Override
    public Map<String, List<MeetingApplication>> queryMore(Map<String, Object> filterMap) {
        List<MeetingApplication> meetingApplications = meetingApplicationMapper.queryMore(filterMap);
        Map<String, List<MeetingApplication>> resultMap = new HashMap<>();
        for (MeetingApplication meetingApplication : meetingApplications) {
            String meetingRoomName = meetingApplication.getMeetingRoomName();
            List<MeetingApplication> applications = resultMap.get(meetingRoomName);
            if (CollectionUtils.isEmpty(applications)) {
                ArrayList<MeetingApplication> list = new ArrayList<>();
                list.add(meetingApplication);
                resultMap.put(meetingRoomName, list);
            } else {
                applications.add(meetingApplication);
            }
        }
        return resultMap;
    }

    /**
     * 查询未审核的会议申请
     * @return
     */
    @Override
    public List<MeetingApplication> queryNoAuditData() {
        return meetingApplicationMapper.queryNoAuditData();
    }

    /**
     * 根据时间段查询会议室是否冲突
     * @param meetingApplication
     * @return
     */
    @Override
    public List<MeetingApplication> queryMeetingByApplicationTime(MeetingApplication meetingApplication) {
        return meetingApplicationMapper.queryMeetingByApplicationTime(meetingApplication);
    }

    /**
     * 查询会议室信息
     * @param filterMap
     * @return
     */
    @Override
    public List<MeetingApplication> queryMeetingRoomInfo(Map<String, Object> filterMap) {
        return meetingApplicationMapper.queryMeetingRoomInfo(filterMap);
    }
}